#ifndef CONTROL_LOOP_H
#define CONTROL_LOOP_H

#include "../pid/PidCotroler.h"
#include "../SVPWM/SVPWM.h"

class ControlLoop {
protected:
    PIController piController;
    SVPWM svpwm;
    float valpha, vbeta;
    float targetValue;
    float actualValue;
public:
    float outputD, outputQ;

public:
    ControlLoop(float kp, float ki, float integralLimit, float outputLimit, float dcBusVoltage = 12.0f);
    virtual ~ControlLoop() = default;

    // 设置目标值
    void setTarget(float target);

    // 设置当前实际值
    void setActualValue(float value);

    // 设置Park反变换结果
    void setParkInverseTransform(float vd, float vq);

    // 执行PI控制和SVPWM调制
    virtual void execute(float angle);

    // 获取SVPWM调制结果
    void getPwmDutyCycle(float angle,float& dutyU, float& dutyV, float& dutyW);

    // 重置控制器状态
    void reset();
};

#endif // CONTROL_LOOP_H